package com.example.shiwuyouproject.ui.fragment

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.example.shiwuyouproject.base.BaseVmFragment
import com.example.shiwuyouproject.databinding.FragmentMyBinding
import com.example.shiwuyouproject.net.http.Api
import com.example.shiwuyouproject.ui.MainActivity
import com.example.shiwuyouproject.ui.bean.GetMessageListsBean
import com.example.shiwuyouproject.ui.fragment.my.MyCollectionActivity
import com.example.shiwuyouproject.ui.fragment.my.activity.*
import com.example.shiwuyouproject.ui.fragment.my.bean.GetUserCenterBean
import com.example.shiwuyouproject.ui.modelview.MyViewModel
import com.example.shiwuyouproject.ui.my.bean.PersonalInformationBean
import com.example.shiwuyouproject.ui.pup.AlbumPopupView
import com.example.shiwuyouproject.ui.pup.LogOutPopupView
import com.example.shiwuyouproject.utils.*
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.config.PictureConfig
import com.luck.picture.lib.config.PictureMimeType
import com.lxj.xpopup.XPopup
import com.yechaoa.yutilskt.ToastUtil

class MyFragment : BaseVmFragment<FragmentMyBinding, MyViewModel>() {
    private var share_img=""
    override fun viewModelClass(): Class<MyViewModel> = MyViewModel::class.java

    override fun getViewBinding(): FragmentMyBinding {
        return FragmentMyBinding.inflate(layoutInflater)
    }

    private var myMain: MainActivity? = null
    override fun initView() {
        myMain = activity as MainActivity?
    }

    override fun onResume() {
        super.onResume()
        if (SPUtils.getInstance().myUserInfo != null) {
            mViewModel.getUserCenter()
            mViewModel.getRealNameAuthenticationData()
        }
    }

    override fun setListener() {
        binding?.profileImage?.setOnClickListener {
            ActStartUtils.startAct(context, PersonalInformationActivity::class.java)
        }
        binding?.tvNickname?.setOnClickListener {
            ActStartUtils.startAct(context, PersonalInformationActivity::class.java)
        }
        binding?.btSetting?.setOnClickListener { //设置
            if (getUserCenterBean == null) {
                return@setOnClickListener
            }
            val mBundle = Bundle()
            mBundle.putString("searchable", getUserCenterBean?.searchable)
            ActStartUtils.startForAct(context as Activity?, SettingActivity::class.java, mBundle,100)
        }
        binding?.tvAuthenticationCenter?.setOnClickListener { //认证中心
            ActStartUtils.startAct(context, AuthenticationCenterActivity::class.java)
        }
        binding?.tvMyIncome?.setOnClickListener { //我的收益
            val mBundle=Bundle()
            mBundle.putString("share_img",share_img)
            ActStartUtils.startAct(context, MyIncomeActivity::class.java,mBundle)
        }
        binding?.tvPersonalData?.setOnClickListener {//个人资料
            ActStartUtils.startAct(context, TeacherInformationActivity::class.java)
        }
        binding?.tvMyApplication?.setOnClickListener { //我的申请
            ActStartUtils.startAct(context, MyApplicationActivity::class.java)
        }
        binding?.tvMyCollection?.setOnClickListener { //收藏列表
            ActStartUtils.startAct(context, MyCollectionActivity::class.java)
        }
        binding?.tvMyComments?.setOnClickListener { //评价
            ActStartUtils.startAct(context, MyCommentsActivity::class.java)
        }
    }

    private var getUserCenterBean: GetUserCenterBean? = null
    override fun observe() {
        mViewModel.getUserCenterState.observe(this, androidx.lifecycle.Observer<GetUserCenterBean>{
            getUserCenterBean = it
            mBinding.tvNickname.text = it.nickname
            mBinding.tvZhiWei.text = it.working
            mBinding.tvGongZuoLeiXin.text = it.zcname
            mBinding.tvXueLi.text = it.degree
            mBinding.tvJiaoShiLeiXin.text = it.part_job
            mBinding.tvVipLiv.text = it.level
            share_img=it.share_img
        })
        mViewModel.getGenRenStatus.observe(this, androidx.lifecycle.Observer<PersonalInformationBean>{
            context?.let { it1 ->
                GlideUtils.fangImgPortrait(
                    it1,
                    mBinding.profileImage,
                    it.avatar
                )
            }
        })
    }

}

